#ifndef SERVER_H
#define SERVER_H

#include <QMainWindow>
#include    <QtNetwork>
#include    <QTcpServer>
#include    <QLabel>

namespace Ui {
class server;
}

class server : public QMainWindow
{
    Q_OBJECT

public:
    explicit server(QWidget *parent = nullptr);
    ~server();

private slots:
    void on_actStop_triggered();
    void on_actClear_triggered();

    //自定义槽函数
    void    onNewConnection();//QTcpServer的newConnection()信号
    void    onSocketStateChange(QAbstractSocket::SocketState socketState);
    void    onClientConnected(); //Client Socket connected
    void    onClientDisconnected();//Client Socket disconnected
    void    onSocketReadyRead();//读取socket传入的数据
    void on_btnSend_clicked();

    void on_actHostInfo_triggered();

    void on_actStart_triggered();

private:
    Ui::server *ui;
    QLabel  *LabListen;//状态栏标签
    QLabel  *LabSocketState;//状态栏标签

    QTcpServer *tcpServer; //TCP服务器
    QTcpSocket *tcpSocket;//TCP通讯的Socket

    QString getLocalIP();// 获取本机IP地址

protected:
    void    closeEvent(QCloseEvent *event);

};

#endif // SERVER_H
